<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guava字符串工具：Java程序员的瑞士军刀</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        pre {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-size: 14px;
            line-height: 1.6;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        
        .inline-code {
            background: #f0f0f0;
            padding: 2px 6px;
            border-radius: 4px;
            font-size: 0.9em;
            color: #e83e8c;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            border-radius: 12px;
            padding: 24px;
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
            animation: shimmer 3s infinite;
        }
        
        @keyframes shimmer {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl font-bold mb-4 tracking-tight">Guava字符串工具</h1>
            <p class="text-2xl mb-8 opacity-90">Java程序员的瑞士军刀</p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-code mr-2"></i>
                    <span>优雅API</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-rocket mr-2"></i>
                    <span>高性能</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>生产就绪</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-5xl">
        <!-- Introduction -->
        <div class="content-card rounded-xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">字</span>符串处理可能是我们日常编程中最常见的任务之一，但Java的原生API总让我觉得少了点什么。自从用上了Guava的Strings工具类，我再也不用为那些繁琐的字符串操作发愁了。它简直就是Java程序员的瑞士军刀！
            </p>
        </div>

        <!-- Guava核心组件概览 -->
        <div class="content-card rounded-xl p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 section-title">Guava字符串工具核心组件</h2>
            <div class="mermaid">
                graph TD
                    A[Guava字符串工具] --> B[Joiner]
                    A --> C[Splitter]
                    A --> D[Strings]
                    A --> E[CharMatcher]
                    
                    B --> B1[连接集合元素]
                    B --> B2[处理null值]
                    B --> B3[添加前缀后缀]
                    
                    C --> C1[分割字符串]
                    C --> C2[去除空白]
                    C --> C3[忽略空串]
                    
                    D --> D1[空值处理]
                    D --> D2[填充对齐]
                    D --> D3[公共前后缀]
                    
                    E --> E1[字符匹配]
                    E --> E2[字符过滤]
                    E --> E3[字符替换]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 1: Joiner/Splitter -->
        <div class="content-card rounded-xl p-8 mb-8">
            <h2 class="text-3xl font-bold mb-8 section-title">1. Joiner/Splitter高效实现原理</h2>
            
            <h3 class="text-xl font-semibold mb-4 text-purple-700">
                <i class="fas fa-question-circle mr-2"></i>1.1 为什么需要更好的字符串连接工具
            </h3>
            
            <p class="text-gray-700 mb-4">在Java中连接字符串看似简单，但传统方法都有各自的缺点：</p>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                <div class="feature-card">
                    <h4 class="font-semibold mb-2"><code class="inline-code">+</code> 操作符</h4>
                    <p class="text-sm text-gray-600">在循环中性能糟糕</p>
                </div>
                <div class="feature-card">
                    <h4 class="font-semibold mb-2"><code class="inline-code">StringBuilder</code></h4>
                    <p class="text-sm text-gray-600">代码啰嗦，处理null值和前缀/后缀麻烦</p>
                </div>
                <div class="feature-card">
                    <h4 class="font-semibold mb-2"><code class="inline-code">String.join</code></h4>
                    <p class="text-sm text-gray-600">JDK 8才有，功能有限</p>
                </div>
            </div>
            
            <p class="text-gray-700 mb-4">特别是处理集合元素连接时，传统做法通常又臭又长：</p>
            
            <pre><code class="language-java">// 传统方式连接List元素
List&lt;String&gt; names = Arrays.asList("张三", "李四", null, "王五");
StringBuilder sb = new StringBuilder();
for (int i = 0; i &lt; names.size(); i++) {
    String name = names.get(i);
    if (name != null) {  // 需要手动处理null
        sb.append(name);
        if (i &lt; names.size() - 1) {  // 避免末尾多余分隔符
            sb.append(", ");
        }
    }
}
String result = sb.toString();</code></pre>
            
            <p class="text-gray-700 mt-4">看到这一堆代码，我就头疼。而且这还没处理前缀后缀等情况。</p>
        </div>

        <!-- Joiner优雅实现 -->
        <div class="content-card rounded-xl p-8 mb-8">
            <h3 class="text-xl font-semibold mb-4 text-purple-700">
                <i class="fas fa-magic mr-2"></i>1.2 Joiner：优雅的字符串连接
            </h3>
            
            <p class="text-gray-700 mb-4">Guava的Joiner提供了流畅的API来解决这个问题：</p>
            
            <pre><code class="language-java">// 使用Joiner
String result = Joiner.on(", ")  // 设置分隔符
    .skipNulls()  // 忽略null值
    .join(names);  // 连接元素

// 结果: "张三, 李四, 王五"</code></pre>
            
            <div class="highlight-box my-6">
                <p class="text-gray-800 font-semibold">
                    <i class="fas fa-lightbulb mr-2"></i>
                    简洁明了，对吧？让我们看看Joiner的核心实现：
                </p>
            </div>
            
            <pre><code class="language-java">// Joiner.java (简化版)
public final class Joiner {
    private final String separator;

    private Joiner(String separator) {
        this.separator = separator;
    }
    
    public static Joiner on(String separator) {
        return new Joiner(separator);
    }
    
    public &lt;A extends Appendable&gt; A appendTo(A appendable, Iterable&lt;?&gt; parts) throws IOException {
        return appendTo(appendable, parts.iterator());
    }
    
    public &lt;A extends Appendable&gt; A appendTo(A appendable, Iterator&lt;?&gt; parts) throws IOException {
        if (parts.hasNext()) {
            appendable.append(toString(parts.next()));
            while (parts.hasNext()) {
                appendable.append(separator);
                appendable.append(toString(parts.next()));
            }
        }
        return appendable;
    }
    
    public String join(Iterable&lt;?&gt; parts) {
        return join(parts.iterator());
    }
    
    public String join(Iterator&lt;?&gt; parts) {
        StringBuilder builder = new StringBuilder();
        try {
            appendTo(builder, parts);
        } catch (IOException e) {
            throw new AssertionError(e); // StringBuilder不应抛出IOException
        }
        return builder.toString();
    }
    
    // 处理null的Joiner
    public Joiner skipNulls() {
        return new Joiner(this) {
            @Override
            CharSequence toString(Object part) {
                return (part == null) ? null : Joiner.this.toString(part);
            }
            
            @Override
            public &lt;A extends Appendable&gt; A appendTo(A appendable, Iterator&lt;?&gt; parts) throws IOException {
                while (parts.hasNext()) {
                    Object part = parts.next();
                    if (part != null) {
                        appendable.append(toString(part));
                        break;
                    }
                }
                while (parts.hasNext()) {
                    Object part = parts.next();
                    if (part != null) {
                        appendable.append(separator);
                        appendable.append(toString(part));
                    }
                }
                return appendable;
            }
        };
    }
}</code></pre>
            
            <div class="grid grid-cols-1 m